#include "Main.h"

byte* ExitWaitPtr;
byte* LineSelectionPtr;
byte* ChangeRealmFunctionPtr;
byte* ServerInfoPtr;

void CServer::Init()
{
	__try {
		ExitWaitPtr = (byte*)(*(dword*)Mem->GetAddress("ExitWaitPtr"));
		LineSelectionPtr = (byte*)(*(dword*)Mem->GetAddress("LineSelectionPtr"));
		ChangeRealmFunctionPtr = Mem->GetAddress("ChangeRealmFunction");
		ServerInfoPtr = (byte*)(*(dword*)Mem->GetAddress("ServerInfoPtr"));
	}
	__except(1) { }
}

char* CServer::GetServerName()
{
	__try {
		return (char*)(ServerInfoPtr + 0x124);
	}
	__except(1) {
		return NULL;
	}
}

char* CServer::GetAccountName()
{
	__try {
		return (char*)(ServerInfoPtr + 0x14);
	}
	__except(1) {
		return NULL;
	}
}

word CServer::GetCurrentRealm()
{
	__try {
		return *(word*)(ServerInfoPtr + 0x0A);
	}
	__except(1) {
		return NULL;
	}
}

void CServer::ChangeRealm(word id)
{
	__try {
		*(word*)(ServerInfoPtr + 0) = id;
		*(dword*)(ExitWaitPtr + 0x12F4) = 3;
		byte* LineSelectionObj = LineSelectionPtr + +0x1018;

		_asm {
			PUSH LineSelectionObj
			MOV ECX,LineSelectionPtr
			CALL ChangeRealmFunctionPtr
		}

		*(dword*)(ExitWaitPtr + 0x12F0) = InternalGetTime() - 10000;
	}
	__except(1) { }
}